<extend name="Layout/ins_page" />
<block name="content">
	{:W('PageHeader/search',array('name'=>'权限分配','search'=>'S'))}
	<div class="oprator-panel">
		<div class="split"></div>
		<a id="btn_save" class="btn">保存</a>
	</div>
	<!-- 列表显示区域  -->
	<div class="sub-frame">
		<form id="form_data" name="form_data" method="post" >
			<div class="sub-sidebar big" style="max-height: 500px;overflow-y: auto;border-top:0px solid #ccc;">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th class="x-checkbox col-3">
							<input class="toggle-select-all" data='user_id[]' type="checkbox"  />
							</th>
							<th>
							<nobr>
								员工编号
							</nobr></th>
							<th>
							<nobr>
								姓名
							</nobr></th>
							<th>
							<nobr>
								部门
							</nobr></th>
							<th class="hidden">
							<nobr>
								职级
							</nobr></th>
							<th>
							<nobr>
								职位
							</nobr></th>
							<th>
							<nobr>
								状态
							</nobr></th>
						</tr>
					</thead>
					<tbody class="tbody">
						<volist name="user_list" id="data">
							<tr id="{$data.id}">
								<td class="x-checkbox col-3 text-center">
								<input type="checkbox" name="user_id[]" value="{$data.id}" />
								</td>
								<td>
								<nobr>
									{$data.emp_no}
								</nobr></td>
								<td>
								<nobr>
									{$data.name}
								</nobr></td>
								<td>
								<nobr>
									{$data.dept_name}
								</nobr></td>

								<td>
								<nobr>
									{$data.position_name}
								</nobr></td>
								<td>
								<nobr>
									{$data.is_del|status}
								</nobr></td>
							</tr>
						</volist>
					</tbody>
				</table>
			</div>
			<div class="sub-content small">
				<input type="hidden" name="id" id="id">
				<input type="hidden" name="pid" id="pid" value="">
				<input type="hidden" name="ajax" id="ajax" value="1">
				<input type="hidden" name="opmode" id="opmode" value="">
				<table class="table table-bordered">
					<thead>
						<tr>
							<th>&nbsp;</th>
							<th>业务权限</th>
						</tr>
					</thead>
					<tbody>
						<volist name="duty_list" id="data">
							<tr id="{$data.id}">
								<td class="col-3 text-center x-checkbox">
								<input  type="checkbox" id="duty_{$data.id}" name="duty_list[]" value="{$data.id}"/>
								</td>
								<td>{$data.name}</td>
							</tr>
						</volist>
					</tbody>
				</table>
			</div>
		</form>
	</div>
</block>
<block name="js">
	<script type="text/javascript">
		layui.use(['global'], function() {
			var $ = layui.jquery;
			var layer = layui.layer;

			set_return_url(null);
			$(".sub-sidebar tbody tr").click(function() {
				$(".sub-sidebar  tr").attr("class", "");
				$(this).attr("class", "active");
				send_ajax("{:U('get_duty_list')}", "id=" + $(this).attr("id"), function(data) {
					showdata(data);
				});
			});

			function showdata(result) {
				$("input[name='duty_list[]']").each(function() {
					$(this).prop('checked', false);
				});
				for (var s in result.data) {
					$("#duty_" + result.data[s].duty_id).prop('checked', true);
				}
			};

			//保存后关闭
			$('#btn_save').on('click', function() {
				if ($("input:checked[name='user_id[]']").length < 1) {
					layer.msg("请选择用户");
					return false;
				};
				if ($("input:checked[name='duty_list[]']").length < 1) {
					layer.msg("请选择权限");
					return false;
				};
				send_form('form_data', '{:U("set_duty")}', '', function(ret) {
					if (ret.status == 1) {
						layer.msg(ret.info);
						//parent.location.reload(true);
					} else {
						layer.msg(ret.info);
						return false;
					}
				});
			});
		});

	</script>
</block>